package com.tydic.mapboxtest.util;

import android.content.Context;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by hechao on 17/4/7.
 */

public class FileUtil {

    public static String getFromAssets(Context context, String fileName) {
        try {
            InputStreamReader inputReader = new InputStreamReader(context.getResources().getAssets().open(fileName));
            BufferedReader bufReader = new BufferedReader(inputReader);
            String line = "";
            String Result = "";
            while ((line = bufReader.readLine()) != null)
                Result += line;
            return Result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    //读大型文件
    public static String readBigFile(Context context,String fileName) throws IOException {
        InputStream is = context.getResources().getAssets().open(fileName);
        int lenght = is.available();
        byte[]  buffer = new byte[lenght];
        is.read(buffer);
        String result = new String(buffer, "utf8");
        return result;
    }
}
